home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
096
/
filer.arc
/
FILER.C
< prev
next >
Wrap
Text File
|
1984-12-23
|
5KB
|
166 lines
/* Finds all SYSTEMxx.BBS files and prints the "directory" list of each
file area, a la Fido. The file areas that are displayed are those
that callers with "normal" or lower privilege can enter.
Note: if you interrupt this program via control-C/control-Break,
you will be left in the subdirectory which was last being processed.
I would suggest issuing a "prompt" command like the following:
prompt $d $t$_$p:
DOS will then give you a two-line prompt consisting of current date
and time and the current path.
This program was compiled using CI-C86 v2.10E.
*/
#include <stdio.h>
#include <bbs.h>
#define MAXLINE 128
extern char *fgets(),
*calloc(),
*gcdir(),
*filedir();
extern FILE *fopen();
extern long fseek();
/**/
/* files(): Reads DIR.BBS and FILES.BBS
Displays to stdout the directory list a la Fido
*/
files()
{
FILE *bbs, *junk;
char *buf, *ch;
long fz;
if((buf=calloc(1,MAXLINE))==NULL) /* get buffer space */
abort("FILER: calloc buf fail");
if((junk=fopen("dir.bbs","r"))==NULL) /* get heading info from DIR.BBS */
printf("no DIR.BBS\n");
else {
while(fgets(buf,MAXLINE,junk)!=NULL)
printf("%s",buf);
fclose(junk);
}
printf("\n");
if((bbs=fopen("files.bbs","r"))==NULL) {/* get filenames from FILES.BBS */
printf("No files\n"); /* tell us about the missing file */
free(buf); /* release buffer space */
return; /* back to caller */
}
while(fgets(buf,MAXLINE,bbs)!=NULL) { /* read each line in FILES.BBS */
ch = buf; /* set ch to begin of buffer */
if(*ch=='@') { /* '@' indicates beginning of uploads */
free(buf); /* release buffer space */
return; /* back to caller */
}
if((*ch==' ')||(*ch=='-')||
(*ch=='\n')) { /* if comment or empty line */
printf("%s",buf); /* just print it out and go */
continue;
}
while(!isspace(*ch++)); /* move ch to end of filename, buf points to filename */
*--ch = EOS; /* terminate the filename portion for fopen() */
ch++;
if((junk=fopen(buf,"rb"))==NULL) { /* does file exist?? */
printf("%-12s MISSING %s",buf,ch); /* show us it's missing */
if(*ch==EOS) printf("\n"); /* no comment means we need a newline */
continue; /* work on next line in FILES.BBS */
}
if((fz=fseek(junk,-1L,2))==-1L) /* exists, get size-1 by fseek() to end of file */
abort("FILER: err in fseek on %s",buf);
fclose(junk); /* release the file */
printf("%-12s %7ld %s",buf,++fz,ch); /* show us its size */
if(*ch==EOS) printf("\n"); /* no comment means we need a newline */
} /* end of while(fgets... */
free(buf); /* release buffer space */
return; /* back to caller */
} /* end of files() */
/**/
main()
{
static char descr[40]="Download Area ";
VSYS vbbs;
FILE *sysv;
int working=TRUE, dirc=0, i;
char *homedir, *curdir,
*tsys, *d,
sysname[16];
#define dpriv vbbs._spriv
#define dpath vbbs._sfilepath
homedir = gcdir(""); /* remember whence we came */
tsys=filedir("system*.bbs",0); /* find all SYSTEMxx.BBS tables */
if(!*tsys) {
free(tsys);
abort("FILER: not in Fido's home directory!");
}
d = tsys; /* note begin of filenames */
while(TRUE) { /* how many did we find? */
if(!*d) { /* end of filename? */
d++; /* yes, note start of next filename */
dirc++; /* and count the name */
}
if(!*d) /* end of all names? */
break; /* yes, exit */
d++; /* go to next character */
}
dirc--; /* accounts for "master" table */
free(tsys); /* don't need filenames now */
/* for each SYSTEMxx.BBS found, if "normal" users are permitted to view the
directory, then move into the indicated subdirectory and read and display
the FILES.BBS a la Fido.
*/
for(i=1; i<=dirc; i++) {
sprintf(sysname,"system%d.bbs",i); /* construct filename */
if((sysv=fopen(sysname,"rb"))==NULL) /* does table file exist? */
abort("FILER: can't open %s",sysname);
if(fread(&vbbs,sizeof(VSYS),1,sysv)!=1)
abort("FILER: error reading %s",sysname);
fclose(sysv); /* don't need file any longer */
if((dpriv>NORMAL)||(dpath[0]==EOS)) { /* skip it if normal users can't get here */
chdir(homedir); /* or if there is not an associated file area */
continue;
}
dpath[strlen(dpath)-1] = EOS; /* kill last character of pathname */
if(chdir(dpath)!=0) /* try to get to subdirectory */
abort("FILER: can't chdir(%s)",dpath);
printf("Download Area #%d\n",i); /* display some description */
files(); /* display FILES.BBS */
chdir(homedir); /* back to home directory */
}
exit(0); /* back to DOS */
} /* end of main() */
/* end of filer.c */